package com.hzqy.service.epg;

import java.util.*;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.hzqy.commons.utils.ActivityUtils;
import com.hzqy.persistence.dao.epg.AcIntegralDao;
import com.hzqy.web.vo.epg.gcw.AcGcwYlVo;
import com.hzqy.web.vo.epg.gcw.AcStbUserVotenum;

@Service
public class AcInterfaceServiceBean {
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	@Resource
	private AcIntegralDao acIntegralDao;
	@Resource
	private AcIntegralService acIntegralService;
	
	/**
	 * 实际处理电信（有料及服务）同步到广电广场舞接口的业务方法
	 * @param ayv
	 * @return
	 */
	public Map<String,String> processGcwGdToCmtt(AcGcwYlVo ayv) {
		Map<String,String> map = new HashMap<String,String>();
		map.put("result_code", "-1");
		map.put("message", "失败");
		
		try {
			LOG.debug("进入广场舞与(有料、服务)接口userid="+ayv.getUserid()+",number="+ayv.getNumber()+",sources="+ayv.getSources()+",inputtime="+ayv.getInputtime());
			//完成持久化操作
			AcStbUserVotenum stbnewNum=new AcStbUserVotenum();
			stbnewNum.setF_asuv_serverid(ayv.getUserid());
			stbnewNum.setF_asuv_votenum(Integer.parseInt(ayv.getNumber()));
			if(ayv.getSources()!=null && ayv.getSources().equals("yl")) //有料接口
				stbnewNum.setF_asuv_source("1");
			else if(ayv.getSources()!=null && ayv.getSources().equals("fw")) //服务
				stbnewNum.setF_asuv_source("2");
			else {
				map.put("message", "来源错误");
				return map;
			}
			stbnewNum.setF_asuv_activityid(ActivityUtils.ACID_RECECHARG);
			stbnewNum.setF_asuv_memo(ayv.getSources());
			stbnewNum.setF_asuv_obligate1(0);
			stbnewNum.setF_asuv_obligate2(ayv.getInputtime());
			stbnewNum.setF_asuv_resolution(0);
			acIntegralService.insertUserVotenum(stbnewNum);
			map.put("result_code", "0");
			map.put("message", "成功");
			/*int flag = acIntegralDao.insertAcStbUserVotenum(stbnewNum);
			if(flag>0) { //判断用户可投流水表记录是否插入成功
				map.put("result_code", "0");
				map.put("message", "成功");
			} else {
				map.put("message", "记录失败");
			}*/
			LOG.debug("返回广场舞与有料接口userid="+ayv.getUserid()+"，result_code="+map.get("result_code")+"，message="+map.get("message"));
			return map;
		} catch(Exception e) {
			LOG.error("广场舞与(有料、服务)接口，负责获取用户在(有料签到、服务开通产品包)的票数同步异常：",e);
		}
		return map;
	}
}
